/*
 * Copyright (C) 2018 YunYu, Inc. All Rights Reserved.
 */
package com.yunyu.kingman.base.common;

/**
 * @author lihui
 * @data 2018/8/8 下午11:40
 */
public class Constant {
    /**
     * KEY分隔符
     */
    public static final String KEY_SAPERATOR = "-";

    /**
     * 分隔符
     **/
    public static final String SPLITOR = "\t";

    /**
     * 竖线分隔符
     */
    public static final String VERTICAL_LINE = "|";

    public static final String KEY_CONSTANT = "KEY";

    public static String LINE_END = System.getProperty("line.separator");

    /**
     * supergw做为server时，将请求过来的HttpServletRequest.getQueryString方法取到的内容放到map里面，key为HTTP_QUERY_STRING
     */
    public static final String HTTP_QUERY_STRING = "HTTP_QUERY_STRING";

    public static final String SEC_SUFFIX = "SEC";

    public static final String LOCK = "_lock";

    public static final String SCHEMA_LOCK = "_schema_lock";

    public static final String SEC_DATA = "_sec_data";

    public static final String FINAL_DATA = "_fin_data";

    /**
     * 二级运算依赖一轮计算单元id分隔符
     */
    public static final String SEC_UNIT_CAC_ID_SPLITOR = ",";

    /**
     * 默认字符集
     */
    public static final String DEFAULT_CHARSET = "GBK";

    /**
     * 每页记录数
     */
    public static final int PAGE_SIZE = 10;

    /**
     * 每页显示最大页码数
     */
    public static final int PAGE_COUNT = 10;

    /**
     * 日志数据redis冗余
     */
    public static final String REPLICA_LOG_DATA = "REPLICA_LOG_DATA_";
    /**
     * AVG运算中SUM值dataKey后缀
     */
    public static final String AVG_CAC_SUM = "AVG_CAC_SUM";
    /**
     * AVG运算中COUNT值dataKey后缀
     */
    public static final String AVG_CAC_COUNT = "AVG_CAC_COUNT";
    /**
     * AVG运算中最大值dataKey后缀
     */
    public static final String AVG_CAC_MAX = "AVG_CAC_MAX";
    /**
     * AVG运算中最小值dataKey后缀
     */
    public static final String AVG_CAC_MIN = "AVG_CAC_MIN";

    /**
     * AVG运算区间最大值对应数据列
     */
    public static final Integer CAC_AVG_MAX_COLUMN = 97;
    /**
     * AVG运算区间最小值对应数据列
     */
    public static final Integer CAC_AVG_MIN_COLUMN = 98;
    /**
     * 计算结果对应数据列
     */
    public static final Integer CAC_RESULT_COLUMN = 99;
    /**
     * 计算结果占比对应数据列
     */
    public static final Integer CAC_PERSENT_COLUMN = 100;

    /**
     * 除法运算分子
     */
    public static final String DIV_CAC_NUMERATOR = "numerator";

    /**
     * 除法运算分母
     */
    public static final String DIV_CAC_DENOMINATOR = "denominator";

    /**
     * 逻辑删除 - 有效标识
     */
    public static final String VALID_FLAG = "Y";

    /**
     * 逻辑删除 - 无效标识
     */
    public static final String INVALID_FLAG = "N";

    /**
     * 逻辑- 是
     */
    public static final String YES = "Y";

    /**
     * 逻辑 - 否
     */
    public static final String NO = "N";

    /**
     * 默认角色
     */
    public static final String DEFAULT_ROLE_NAME = "IS_AUTHENTICATED_ANONYMOUSLY";

    /**
     * warden store data seq
     */
    public static final String WARDEN_STORE_DATA_SEQ = "STORE_DATA_SEQ";

    /**
     * 统计维度列名前缀
     */
    public static final String COL_PREFIX = "col";

    /**
     * map数据至redis set的名称前缀
     */
    public static final String SADD_REDUCE_SUFFIX = "SET_REDUCE";
    /**
     * 二级运算数据至redis set的名称前缀
     */
    public static final String SADD_SEC_REDUCE_SUFFIX = "SET_SEC_REDUCE";
    /**
     * datapool内存数据至redis set的名称
     */
    public static final String SADD_RELEASE_TEMP = "SET_RELEASE_TEMP";
    /**
     * 4小时对应秒数
     */
    public static final int FOUR_HOUR_SECONDS = 4 * 60 * 60;
    /**
     * 1小时对应秒数
     */
    public static final int ONE_HOUR_SECONDS = 60 * 60;
    /**
     * map过期数据延迟前缀
     */
    public static final String HISTORY_DATA_MAP_DELAY = "HISTORY_DATA_MAP_DELAY";
    /**
     * reduce过期数据延迟前缀
     */
    public static final String HISTORY_DATA_REDUCE_DELAY = "HISTORY_DATA_REDUCE_DELAY";

    /**
     * 配置文件中存放系统运行模式的属性KEY
     */
    public static final String RUN_MODE_PROPERTY_KEY = "run.mode";

    /**
     * 运行模式：生产模式
     */
    public static final String MODE_PROD             = "prod";

    /**
     * REST服务URL的固定开头
     */
    public static final String SERVICES_URL_PREFIX   = "/services";

    /**
     * 禁用构造函数
     */
    private Constant() {
        // 禁用构造函数
    }

    /**
     * 组装KEY值，默认使用'\t'作为分割符号
     *
     * @param inputs
     *
     * @return
     */
    public static String getKey(String... inputs) {
        return getKeyWithSep(SPLITOR, inputs);
    }

    /**
     * 组装KEY值
     *
     * @param saperator
     * @param inputs
     *
     * @return
     */
    public static String getKeyWithSep(String saperator, String... inputs) {
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < inputs.length; i++) {
            String input = inputs[i];
            result.append(input);

            if (i != inputs.length - 1) {
                result.append(saperator);
            }
        }

        return result.toString();
    }
}
